package com.example.networkinteraction.observer;

import com.example.networkinteraction.manager.RxRequestManager;
import com.example.networkinteraction.response.BasicResponse;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Description:
 * File: BaseObserver.java
 * Author: Administrator
 * Create: 2019/4/2 0002 下午 13:30
 */
public abstract class BaseObserver<T extends BasicResponse> implements Observer<T> {
    @Override
    public void onSubscribe(Disposable d) {
        RxRequestManager.getInstance().add(setTag(), d);
    }

    protected abstract String setTag();

    @Override
    public void onNext(T t) {
        if (t.isFlag()) {
            onSuccess(t);
        } else {
            onFail(t);
        }
    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onComplete() {

    }

    //成功的回调
    public abstract void onSuccess(T t);

    //失败的回调
    public abstract void onFail(T t);

}
